package com.modules.web;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by lewis on 2017/7/15.
 */


    //private static final String	EASYUI_DATAGRID_TOTAL		= "total";
public   class CRUDController {
   private static final String	BOOTSTRAP_TATAL	= "total";

    private static final String	BOOTSTRAP_ROW	= "rows";


    @RequestMapping(value = "/query", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> query(HttpServletRequest request) throws Exception {

        Page page = onPrepareQueryData(request);
        return  transferTo(page);
    }

    protected Page onPrepareQueryData(HttpServletRequest request) throws Exception {
        return null;//用来查询相关的数据
    }

    protected Map<String, Object> transferTo(Page page) throws Exception {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put(BOOTSTRAP_ROW, page.getContent());
        result.put(BOOTSTRAP_TATAL, page.getTotalElements());
        return result;
    }

}
